<?php
require_once("../config.php");

//if(!isset($_SESSION['admin_user'])) header("location:index.php");

//header("location:admin.php?belongto=season");
//require_once(CONSTANT."alltype.php");
//page_constant("admin");
if(!isset($_GET['id'])) 
	$sql="SELECT * FROM product  WHERE status = 'off'";
else
	$sql="select * from product where id in (SELECT distinct(product.id) FROM product,pic where product.id = pic.productid and pic.userid =".$_GET['id']." and product.status = 'off')";
$dsql->SetQuery($sql);
$dsql->Execute();
while($row=$dsql->GetArray())
	$allproduct[]=$row;
$dsql->SetQuery("select * from alltype");
$dsql->Execute();
while($row=$dsql->GetArray())
	$alltype[]=$row;

foreach ($alltype as $key => $value)
{
	$type[$value['id']]=$value['typename'];
}
foreach($allproduct as $key=>$value)
{
	$productid=$value['id'];
	$dsql->SetQuery("SELECT file FROM pic  WHERE productid = $productid");
	$dsql->Execute();
	$allfiles=array();
	while($row=$dsql->GetArray())
		$allfiles[]=$row['file'];
	$product[$key]["file"]=$allfiles;
	
	$username= $dsql->getone("select username from backuser where id = (select userid from pic where productid = $productid limit 1)");
	$product[$key]["username"]=$username;
	
	$dsql->SetQuery("select * from ".$value['category']." where productid = $productid");
	$dsql->Execute();
	while($row=$dsql->GetArray())
		$allother=$row;
	
	foreach($value as $k=>$item)
	{
		if(is_numeric($item) and $k!="status" and $item!=0 and $k!="id" and $k!="brand")	
				$product[$key][$k]=$type[$item];
		elseif(strlen($item)>1 and $k!="status" and $k!="market_time" and $k!="brand"
			or $k=="id"
			or $k=="market_time" and $item != 0 
			)
			$product[$key][$k]=$item;
		elseif($k=="brand" and $item!=0)
		{
			$brandid=$dsql->getone("select name_en from brand where id = $item");
			$product[$key][$k]=$type[$brandid];
		}
	}
	
	foreach($allother as $k=>$item)
	{
		if(is_numeric($item) and $k!="status" and $item!=0 and $k!="productid")	
				$product[$key][$k]=$type[$item];
		elseif(strlen($item)>1 )
			$product[$key][$k]=$item;
	}
}
//$tpl->assign("type",$type);
$tpl->assign("product",$product);

$tpl->display("admin_check.tpl");


//var_dump($product);
//var_dump($allproduct);



?>